from trainer import AdvancedTrainer
import os

if __name__ == "__main__":
    # 自定义配置
    custom_config = {
        'res_blocks': 10,
        'batch_size': 1024,
        'num_games': 5000,
        'patience': 7,
        'initial_lr': 0.005,
        'curriculum_threshold': 10,
        'elo_k_factor': 24
    }

    # 恢复模型的路径
    resume_model_path = "checkpoint/checkpoint_epoch_10.pth"

    # 初始化训练器
    trainer = AdvancedTrainer(custom_config, resume_model_path)
    
    # 生成训练数据（如果不存在）
    if not os.path.exists(os.path.join(trainer.data_dir, "states.npy")):
        trainer.generate_training_data()
    
    # 开始训练
    try:
        trainer.train(total_epochs=100, resume=False)
    except Exception as e:
        print(f"⚠️ 训练异常终止: {str(e)}")